package titt.service.content.listener;

import titt.util.io.pipe.PipeListener;

public class CombinedListener implements PipeListener {

	private PipeListener a,b;
	
	public CombinedListener(PipeListener... listeners) {
		this(0, listeners);
	}
	
	private CombinedListener(int pointer, PipeListener[] listeners) {
		a = listeners[pointer];
		b = pointer < listeners.length - 1? new CombinedListener(pointer + 1, listeners) : null;
	}
	
	@Override
	public void onComplete(int total) {
		a.onComplete(total);
		if(b != null)
			b.onComplete(total);
	}

	@Override
	public void onConnectionUpdate(int read, int total) {
		a.onConnectionUpdate(read, total);
		if(b != null)
			b.onConnectionUpdate(read, total);
	}

	@Override
	public void onError() {
		a.onError();
		if(b != null)
			b.onError();
	}

	@Override
	public void onInitiate(int total) {
		a.onInitiate(total);
		if(b != null)
			b.onInitiate(total);
	}

}
